package com.iscas.tech.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iscas.tech.entity.AtBaseuser;
import com.iscas.tech.mapper.AtBaseuserMapper;
import com.iscas.tech.param.AtBaseuserPageParam;
import com.iscas.tech.service.AtBaseuserService;
import com.iscas.tech.vo.AtBaseuserQueryVo;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.pagination.PageUtil;
import io.geekidea.springbootplus.framework.pagination.Paging;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 前端用户注册表 服务实现类
 *
 * @author yangyi
 * @since 2020-10-26
 */
@Slf4j
@Service
public class AtBaseuserServiceImpl extends BaseServiceImpl<AtBaseuserMapper, AtBaseuser> implements AtBaseuserService {

    @Autowired
    private AtBaseuserMapper atBaseuserMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveAtBaseuser(AtBaseuser atBaseuser) throws Exception {
        return super.save(atBaseuser);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateAtBaseuser(AtBaseuser atBaseuser) throws Exception {
        return super.updateById(atBaseuser);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteAtBaseuser(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<AtBaseuserQueryVo> getAtBaseuserPageList(AtBaseuserPageParam atBaseuserPageParam) throws Exception {
        Page page = PageUtil.getPage(atBaseuserPageParam, OrderItem.desc(getLambdaColumn(AtBaseuser::getCreatetime)));
        IPage<AtBaseuserQueryVo> iPage = atBaseuserMapper.getAtBaseuserPageList(page, atBaseuserPageParam);
        return new Paging(iPage);
    }

    @Override
    public Boolean checkUser(Long id) throws Exception {
        return atBaseuserMapper.checkUser(id);
    }

    @Override
    public List<AtBaseuserQueryVo> searchUser(String keyword) {
        return atBaseuserMapper.searchUser(keyword);
    }

}
